package com.ezjie.ielts.module_read.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ezjie.ielts.R;
import com.ezjie.ielts.model.ReadClassifyDetail;
import com.ezjie.ielts.view.CircleProgressView;

public class ReadClassisyAdapter extends BaseAdapter {

	private Context mContext;
	private List<ReadClassifyDetail> lists = new ArrayList<ReadClassifyDetail>();

	public ReadClassisyAdapter(Context context) {
		mContext = context;
	}

	public void setDatas(List<ReadClassifyDetail> lists) {
		this.lists = lists;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return lists.size();
	}

	@Override
	public ReadClassifyDetail getItem(int position) {
		return lists.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (null == convertView) {

			holder = new ViewHolder();
			convertView = View.inflate(mContext, R.layout.layout_read_classify_grid_item, null);

			holder.progressView = (CircleProgressView) convertView.findViewById(R.id.cv_read_classify_rate);
			holder.titleView = (TextView) convertView.findViewById(R.id.tv_read_classify_title);
			holder.detailView = (TextView) convertView.findViewById(R.id.tv_read_classify_detail);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		ReadClassifyDetail info = getItem(position);

//		holder.progressView.setProgressValues(Float.valueOf(info.answer_num), Float.valueOf(info.total));
//		holder.detailView.setText(String.format(mContext.getResources().getString(R.string.read_classify_item_detail),
//				Integer.valueOf(info.right_num), Integer.valueOf(info.total)));
		holder.progressView.setProgressValues(Float.valueOf(info.answer_question_num), Float.valueOf(info.total_question));
		holder.detailView.setText(String.format(mContext.getResources().getString(R.string.read_classify_item_detail),
				Integer.valueOf(info.right_question_num), Integer.valueOf(info.total_question)));
		holder.titleView.setText(info.cn);

		return convertView;
	}

	class ViewHolder {
		CircleProgressView progressView;
		TextView titleView;
		TextView detailView;
	}

}
